Repository navigation
[CMake] Add BYN_PGO_GENERATE and BYN_PGO_PROFILE_USE_FILE options - #9420
Conversation
Add CMake options for 2-phase IR Profile-Guided Optimization (PGO) builds with Clang: - `BYN_PGO_GENERATE`: Adds `-fprofile-generate` to compile flags. On Windows with `clang-cl` (`MSVC`), CMake invokes `lld-link` directly rather than linking through the compiler driver, so query `clang-cl` for its compiler-rt directory and pass `/libpath:"<dir>"` so `lld-link` resolves the embedded `clang_rt.profile-*.lib` directive; on other platforms, pass `-fprofile-generate` to the linker driver. - `BYN_PGO_PROFILE_FILE`: Adds `-fprofile-instr-use="<path>"` and `-Wno-backend-plugin` (to avoid harmless `main()` CFG hash-mismatch warnings across tools other than `wasm-opt` when `-Werror` is enabled) to compile flags, and passes `-fprofile-instr-use="<path>"` to link flags on non-MSVC platforms.
|
We'll use this for the emscripten-releases release-optimized builds. So... maybe we can get away without CI coverage for this on the Binaryen side? |
tlively
left a comment
There was a problem hiding this comment.
BYN_PGO_PROFILE_FILE => BYN_PGO_PROFILE_USE_FILE in the title.
| # linking through the compiler driver. clang-cl embeds a /DEFAULTLIB | ||
| # directive for clang_rt.profile-*.lib in each object file, so add clang's | ||
| # compiler-rt directory to the linker library search path. | ||
| # Note: COMMAND_ERROR_IS_FATAL requires CMake 3.19+. |
There was a problem hiding this comment.
Should we update our minimum required cmake version accordingly? Right now it is 3.16.3. Alternatively, we could more manually check return codes (like we do with git rev-parse above) without requiring a newer cmake.
There was a problem hiding this comment.
Ah yes actually i was going to file a bug about that today. LLVM is currently requiring 3.20, and starting with LLVM 24 it will be 3.31. It might make sense for us to follow that, as LLVM generally has pretty conservative build requirements. Gemini also noted that mimalloc and fuzztest have higher requirements than Binaryen itself (although those are of course optional). It suggested some minor improvements we could make if we went to 3.20 and several more simplifications we could make if we went to 3.31.
Looking at several LTS versions, it looks like the oldest default CMake from the selection is Ubuntu Jammy with 3.22.
There was a problem hiding this comment.
Ok, LGTM to land this as-is while we discuss which version to update to, then.
kripken
left a comment
There was a problem hiding this comment.
Maybe worth adding a test at some point, though if this is still in flux it can wait?
|
The plan is that this will be covered by our release build on the emscripten-releases side. We already have some flags e.g. BUILD_SHARED_LIBS that are only tested there and not on CI here; I think the risk is low since breakage won't go undiscovered for long. |
Add CMake options for 2-phase IR Profile-Guided Optimization (PGO)
builds with Clang:
BYN_PGO_GENERATE: Adds-fprofile-generateto compile flags. OnWindows with
clang-cl(MSVC), CMake invokeslld-linkdirectlyrather than linking through the compiler driver, so query
clang-clfor its compiler-rt directory and pass
/libpath:"<dir>"solld-linkresolves the embeddedclang_rt.profile-*.libdirective;on other platforms, pass
-fprofile-generateto the linker driver.BYN_PGO_PROFILE_FILE: Adds-fprofile-instr-use="<path>"and-Wno-backend-plugin(to avoid harmlessmain()CFG hash-mismatchwarnings across tools other than
wasm-optwhen-Werroris enabled)to compile flags, and passes
-fprofile-instr-use="<path>"to linkflags on non-MSVC platforms.